<template>
  <div>
    <el-form :model="{}" size="medium" :inline="true" label-width="60px">
      <el-form-item label="操作栏" prop="">
        <el-button :disabled="selection.length === 0" type="primary" plain icon="el-icon-plus" size="medium"
          @click="Commit">添加</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="noticeList" @selection-change="handleSelectionChange" @row-click="clickRow"
      ref="tb">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column label="序号" align="center" prop="order" width="50" />
      <el-table-column label="编号" align="center" prop="noticeType" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.typeNum || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="名称" align="center" min-width="120">
        <template slot-scope="scope">
          {{ scope.row.typeName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="周期" align="center" min-width="120">
        <template slot-scope="scope">
          {{ ['一日', '一周', '十五日', '一月', '三月', '六月', '十二月', '不定'][scope.row.cycle] || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="排序" align="center" min-width="120">
        <template slot-scope="scope">
          {{ scope.row.sort || '-' }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="状态" align="center" min-width="120">
        <template slot-scope="scope">
          <dict-tag :options="statusFlag" :value="scope.row.status" />
        </template>
      </el-table-column> -->
      <el-table-column label="备注" align="center" min-width="180">
        <template slot-scope="scope">
          {{ scope.row.remark || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="创建部门" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.deptName || '-' }}
        </template>
      </el-table-column>
    </el-table>
    <!-- <div class="card-div"> -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- </div> -->
  </div>
</template>

<script>
import { getUpkeepTypeList, putUpdatechangeStatus } from "@/api/maintenance/insurance/insurance.js";

export default {
  components: {
  },
  data () {
    return {
      // 遮罩层
      loading: true,
      opendetailed: false,
      detailedObj: {},
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      dictdatalist: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层表格数据
      noticeList: [],
      rowObj: {},
      // 弹出层标题
      title: "修改保养类型",
      // 是否显示弹出层
      open: false,
      selection: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'upkeepTypeId',
        isAsc: 'desc',//倒叙
        status: '0'
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        noticeTitle: [
          { required: true, message: "公告标题不能为空", trigger: "blur" }
        ],
        noticeType: [
          { required: true, message: "公告类型不能为空", trigger: "change" }
        ]
      }
    };
  },
  created () {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    async getList (value) {
      this.loading = true;
      let params = {
        ...this.queryParams,
        ...value
      }
      //  let data = await getdatalist({ dictType: 'base_unit' })
      //  this.dictdatalist=data.data
      getUpkeepTypeList(params).then(response => {
        this.noticeList = response.data && response.data.map((item, index) => {
          return {
            ...item,
            order: index + 1
          }
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    clickRow (row) {//单击行选中前面复选框
      this.$refs.tb.toggleRowSelection(row);
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 打开详细弹窗
    handledetailed (row) {
      this.opendetailed = true
      this.detailedObj = row
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.rowObj = row
      this.open = true
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.selection = selection
    },
    Commit () {
      this.$emit('clearOpenStandard', this.selection)
    },
    /** 启用禁用按钮操作 */
    handleDelete (row) {
      const noticeIds = row.typeName || '无名称'
      this.$confirm(`是否确认${row.status === '0' ? `禁用` : `启用`}名称为${noticeIds}的数据？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        let params = {
          upkeepTypeId: row.upkeepTypeId,
          status: row.status === '0' ? 1 : 0
        }
        putUpdatechangeStatus(params).then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.getList()
          }
          this.loading = false;
        }).catch(() => { this.loading = false; });
      }).catch(() => { this.loading = false; });
    }
  },
  filters: {
  }
};
</script>
<style lang="scss" scoped>
.red {
  color: red;
}
</style>